<?php
include 'util/BeanJSONEncoder.php';
include 'util/BeanJSONDecoder.php';

class DialogController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // dispatch 
		if ($this->getRequest()->isPost()) {
			$request_body = @file_get_contents('php://input');
			$this->doPost($request_body);
		} else {
			$this->doGet();
		}
		exit;
    }

    private function doPost($request_body) {
    	$dialog = Application_util_BeanJSONDecoder::decode($request_body, Zend_Json::TYPE_OBJECT);
    	
    	$ps = new Application_Model_PersistenceService();
    	$ps->saveDialogTransfer($dialog);
    	
    	$json = Application_util_BeanJSONEncoder::encode($dialog);
		$this->getResponse()->setHeader('Content-Type', 'application/json')
                            ->setBody($json)->sendResponse();
    }

}

